package cn.db101.dao;

import cn.db101.model.reader;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * ����Dao�� 
 * @author ASUS
 *
 */
public class readerDao {
	/**
	 * ��¼��֤
	 * @param con
	 * @param adm
	 * @return
	 * @throws Exception
	 */
	public static reader login(Connection con, reader rea)throws Exception{
		 reader resultrea=null;
		String sql="select * from reader where reader_no=? and password=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, rea.getReader_no());
		pstmt.setString(2, rea.getPassword());
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()) {
			resultrea=new reader();
			resultrea.setReader_no(rs.getString("reader_no"));
			resultrea.setPassword(rs.getString("password"));
		}
		return resultrea;
	}
	/**
	 * �˻�ע��
	 * @param con
	 * @param rea
	 * @return
	 * @throws Exception
	 */
	public static int register(Connection con,reader rea)throws Exception{
		int borrow_num=0;//����Ĭ��ֵ
		int reader_type=2;
		int exist_num=0;
		int del=0;
		String sql="insert into reader values(?,?,?,?,?,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1,rea.getReader_no());
		pstmt.setString(2,rea.getPassword());
		pstmt.setString(3,rea.getReader_name());
		pstmt.setString(4,rea.getGender());
		pstmt.setInt(5,borrow_num);
		pstmt.setInt(6,reader_type);
		pstmt.setInt(7,exist_num);
		pstmt.setString(8,rea.getDapartment());
		pstmt.setInt(9,del);
		return pstmt.executeUpdate();
	}
}
